﻿<cfscript>
/** 
* ORM ProgramTask
* 
* @hint "Hibernate persistenter t_task. 学期教学任务安排表" 
* 
*/ 

component 
	displayname="public.service.orm.senate.ProgramTask" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="ProgramTask" 
	table="t_task"
	{

	property type="string" name="TaskID" column="tsk_id" fieldtype="id" generator="assigned" hint="教学任务号";

	property type="string" name="CourseIndex" column="cidx" hint="课序号";
	property type="string" name="TaskWeek" column="task_week" hint="上课周次";
	property type="string" name="TaskPeriod" column="task_period" hint="排课周学时";
	property type="string" name="TaskTime" column="task_time" hint="上课时间列表";
	property type="string" name="TaskPlace" column="task_place" hint="上课地点列表";
	property type="numeric" name="TaskCapacity" column="task_capacity" hint="教学班容纳学生人数上限";
	property type="numeric" name="PlanSize" column="task_limite" hint="选课人数限定";
	property type="numeric" name="RealSize" column="task_chooesd" hint="听课总人数";
	property type="string" name="Describe" column="task_desc" hint="排课要求";
	property type="string" name="ArrangeMode" column="task_mode" hint="排课模式";
	property type="string" name="Classes" column="task_classes" hint="教学任务行政班组成情况";

	property type="string" name="TaskProps" column="task_prop" hint="教学任务相关属性";

	property name="Term" fieldtype="many-to-one" fkcolumn="term_id" cfc="Term"  hint="学期";
	property name="Course" fieldtype="many-to-one" fkcolumn="cid" cfc="Course"  hint="课程";
	property name="Teacher" fieldtype="many-to-one" fkcolumn="tch_id" cfc="Teacher"  hint="主讲教师";
	property name="Campus" fieldtype="many-to-one" fkcolumn="campus_id" cfc="Campus" hint="校区";
	property name="ClassroomType" fieldtype="many-to-one" fkcolumn="cr_type" cfc="ClassroomType"  hint="教室类型";
	property name="TeacherSecondary" fieldtype="many-to-one" fkcolumn="tch_id_sec" cfc="Teacher"  hint="第二主讲教师";
	property name="TeacherAssist" fieldtype="many-to-one" fkcolumn="tch_id_ace" cfc="Teacher"  hint="助课教师";

	/**
	* @hint "生成课序号"
	* 
	* @Term "学期"
	* @Course "课程"
	*/
	public string function getCourseIDX( required Term, required Course ) output=false {
		/* 
			课序号规则 3位代码
		*/
		var nextID = numberFormat(1, "0__");
		
		var checkArray = ORMExecuteQuery("select CourseIndex from ProgramTask 
											where 
											Course = :course 
											and 
											Term = :term 
											order by CourseIndex desc", {course=arguments.Course, term=arguments.Term}, { maxResults=1 });
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = numberFormat((checkArray[1] + 1), "0__");
		}

		return nextID;
	}
	
	/**
	* @hint "自定义主键规则"
	* 
	* @Term "学期"
	* @Course "课程"
	* @CourseIndex "课序号"
	*/
	public string function getID( required Term, required Course, required string CourseIndex ) output=false {
		
		var nextID = arguments.Term.getTermID() & "," & arguments.Course.getCourseID() & "," & arguments.CourseIndex;

		/* 
			主键生成规则 
			
			培养方案号18位 3位学期代码 , 6位课程号 , 3位课序号

			Unique: TERM_ID, CID, CIDX
		*/
		return nextID;
	}
}

</cfscript>